//文章内容
import React from "react";
import axios from "axios"
import * as Public from "../publicComponents/index"
import { useState,useEffect,useRef } from "react";
import { Comment } from "../publicComponents/index";
import { Children } from "react";
export function ArticleDetail({articleId,requestData,renderId}:{articleId:string,requestData:Function,renderId:string}){
    let nodeRef:any=useRef(null)
    if(!articleId){
        let lo:any=window['location']
        let processID:any=new URL(lo)
        if(processID.search){
            try{
                let nodeRex= new RegExp('(^|&)?' + 'articleId' + '=([^&]*)(&|$)', 'i')
                articleId=processID.search.match(nodeRex)[2]
            }catch{

            }
        }
    }
    useEffect(()=>{
        requestData(articleId)
        window['netRequest']({
            url:"/readArticle/"+articleId,
            method:"GET",
        }).then(res=>{
            let html:any=new DOMParser().parseFromString(res.data,'text/html')
            nodeRef.current.innerHTML=res.data
            //setContent(html)
            console.log(html)
            console.log(res)
        }).catch(err=>{
            console.log(err)
        })
    },[])
    if(articleId==''){
        return (
            <div className="articleDetail">请求参数错误</div>
        )
    }
    return (
        <div style={{margin:'20px',width:'calc(100% - 40px)'}}>
            <Public.TopBar>
                <div className="topCotainer">首页 / 正文</div>
            </Public.TopBar>
            <Comment background='var(--bg-1)' style={{marginTop:'20px',padding:0,width:'100%'}}>
                <div ref={nodeRef} className="articleDetail"></div>
                <div className="pageChange">
                    <div className="pageChangeButton" style={{left:0}}>上一篇</div>
                    <div className="pageChangeButton" style={{right:0}}>下一篇</div>
                </div>
            </Comment>
        </div>
    )
}